package com.csoa.community.requests;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;

import com.csoa.community.bean.ApprovalBean;
import com.csoa.community.net.ErrorMsg;
import com.csoa.community.utils.Json;
import com.csoa.community.utils.StringUtils;

public class OffDocApprovalRequest extends AbstractRequest {

	public List<ApprovalBean> mApprovals;
	public StringBuffer strBuffer;
	public OffDocApprovalRequest(List<BasicNameValuePair> requestValues) {
		super(OFFICIAL_DOC_APPROVAL_METHOD, requestValues);
	}
	
	public OffDocApprovalRequest() {
		
	}

	

	@Override
	protected void parseRemaingInfo(String json) throws ErrorMsg, JSONException {
		if(!StringUtils.isEmpty(json)) {
			if(json.equals("[]")) {
				mApprovals = new ArrayList<ApprovalBean>();
				strBuffer = new StringBuffer();
				return;
			}
			String strJson = "{value:"+json +"}";
			Json jsonAttachs = new Json(strJson);
			mApprovals = new ArrayList<ApprovalBean>();
			fillAttachList(jsonAttachs,mApprovals);
		}
		
	}
	
	
	public void fillAttachList(Json json, List<ApprovalBean> aApprovalBeans) {
		Json[] jsons = json.getJsonArray("value");
		strBuffer = new StringBuffer();
		for (int i=0;i<jsons.length;i++) {
			ApprovalBean approvalBean = new ApprovalBean();
			approvalBean.ReceiverName = jsons[i].getString("ReceiverName");
			approvalBean.ReplyDate = jsons[i].getString("ReplyDate");
			approvalBean.Content = jsons[i].getString("Content");
			aApprovalBeans.add(approvalBean);
			strBuffer.append(approvalBean.ReceiverName + "  " + approvalBean.ReplyDate + "\n" + approvalBean.Content + "\n\n");
		}
		
	}
}
